<template>
  <div class="homework-detail-container">

    <div class="homework-detail-subtitle">
      奖项详情:
    </div>
    <el-table
      :data="awardItemList"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="奖项编号" width="95">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="奖项备注">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="授权单位">
        <template slot-scope="scope">
          <span>{{ scope.row.organizationId }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" label="申请人" width="200" align="center">
        <template slot-scope="scope">
          <span>{{ username }}</span>
        </template>
      </el-table-column>
    </el-table>
    <div class="homework-detail-subtitle">
      申请材料:
    </div>
    <el-collapse v-model="activeNames" @change="handleChange">
      <div v-for="(item,index) in paperList" @click="showDetail(index)">
        <el-collapse-item :title="'奖项' + (index+1)" :name="index" >
          <div>{{item.id}}</div>
          <div></div>
        </el-collapse-item>
      </div>

    </el-collapse>
    <div class="btn-container">
      <el-button type="success" @click="pass">通过</el-button>
      <el-button type="danger" @click="reject">不通过</el-button>
    </div>
  </div>
</template>

<script>
  import {
    deleteOneHomeworkAttachfile,
    getHomeworkAttachFileListByHid,
    getOneHomework, queryOneAward, updateOneHomework,
    uploadHomeworkAttachFile, uploadHomeworkSubmitFile,
  } from "../../api";
  import {HOST, organizationMap, ROLE_KEY, UID_KEY, UNAME_KEY} from "../../constants";
  import {submitApplication} from "../../api/student";
  import {
    teacherCheckApplication,
    teacherQueryApplication,
    teacherQueryOneApplication,
    teacherQueryPaper
  } from "../../api/admin";

  export default {
    name: 'HomeworkDetail',
    data() {
      return {
        username: localStorage.getItem(UNAME_KEY),
        awardItemList: [],
        activeNames: [],
        paperList: [],
      };
    },
    methods: {
      showDetail(index) {
        console.log(this.paperList[index].id)
        teacherQueryPaper(this.paperList[index].id).then(res => {
          console.log(res)
        })
      },
      getOrganizationName(id) {
        return organizationMap[id.toString()]
      },
      handleChange(val) {

      },
      pass() {
        let data = {
          applicationId: '10001',
          status: 'PASS'
        }
        teacherCheckApplication(data).then(res => {
          console.log(res)
        })
      },
      reject() {
        let data = {
          applicationId: '10001',
          status: 'REJECT'
        }
        teacherCheckApplication(data).then(res => {
          console.log(res)
        })
      }
    },
    mounted() {
      this.role = localStorage.getItem(ROLE_KEY)
      console.log(this.$route.params.id)
      teacherQueryOneApplication(this.$route.params.id).then(res => {
        let data = res.data
        console.log(data)
        queryOneAward(data.awardId).then(res => {
          let data = res.data
          data.organizationId = organizationMap[data.organizationId.toString()]
          this.awardItemList.push(data)
        })
        let paperList = data.awardPaperId
        for(let i = 0; i < paperList.length; ++i) {
          let obj = {}
          obj.id = paperList[i]
          this.paperList.push(obj)
        }
      })
    }
  }
</script>

<style lang="scss" scoped>
  .btn-container {
    margin-top: 30px;
  }
  .submit-container {
    margin-top: 20px;
  }
  .homework-detail {
    &-container {
      margin: 30px;
    }
    &-title {
      font-size: 30px;
      line-height: 46px;
    }
    &-text {
      margin-top: 15px;
      font-weight: 400;
      font-size: 16px;
    }
    &-subtitle {
      font-size: 24px;
      margin-top: 25px;
      margin-bottom: 20px;
    }
    &-attachfile-list {
      margin-top: 20px;
      display: flex;
      flex-wrap: wrap;
    }
    &-attachfile-item {
      display: flex;
      margin-bottom: 10px;
      margin-right: 15px;
    }
  }
  .edit-btn {
  }
</style>
